home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conqs3.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  15KB  |  454 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6. get_char(C)
  7. char *C;
  8. {
  9. char result;
  10. Read(raw_fd, &result, 1);
  11. if(result == 0x0d) result = '\n';
  12. *C = toupper(result);
  13. printf("%c", *C);
  14. }
  15.  
  16. get_line(iline, Ind0, onech)
  17. char *iline;
  18. int *Ind0;
  19. int onech;
  20. {
  21.         char ch;
  22.         int ind;
  23.  
  24.         ind=1;
  25.         do {
  26.                 get_char(&ch);
  27.                 if ( ch == '\b' ) { /*backspace*/
  28.                         if ( ind!=1 ) {
  29.                                 ind = ind - 1;
  30.                                 if ( (ind != 1) && onech ) {
  31.                                         putchar('\b');
  32.                                         ind = ind - 1;
  33.                                 };
  34.                                 if ((ind != 1) && !onech) {
  35.                                         putchar(' ');
  36.                                         putchar('\b');
  37.                                 }
  38.                         };
  39.                 } 
  40.                 else if ( ch != '\n' ) {
  41.                         iline[ind] = ch;
  42.                         ind = ind + 1;
  43.                         if ( onech ) {
  44.                                 putchar(' ');
  45.                                 iline[ind] = ' ';
  46.                                 ind = ind + 1;
  47.                         };
  48.                 };
  49.         } 
  50.         while (ind < 25 && ch != '\n');
  51.         while (ind != 80) {
  52.                 iline[ind] = ' ';
  53.                 ind = ind + 1;
  54.         };
  55.         *Ind0 = 1;
  56. }
  57.  
  58. double sqrt();
  59. get_stars(s_star, slist, C0unt)
  60. float slist[nstars+1];
  61. int *C0unt;
  62. {
  63.         int starnum, count;
  64.         float this_range, range2;
  65.  
  66.         count=0;
  67.         for ( starnum = 1 ; starnum <= nstars; starnum++ ) {
  68.                 if ( range[0] >= r2nge[s_star][starnum] ) {
  69.                         count=count+1;
  70.                         slist[starnum] = r2nge[s_star][starnum];
  71.                 } 
  72.                 else
  73.                         slist[starnum] = 0;
  74.         };
  75.         *C0unt = count;
  76. }
  77.  
  78. clear_field()
  79. {
  80.         int new_bottom, y;
  81.         new_bottom = y_cursor - 1;
  82.         if ( new_bottom < bottom_field ) {
  83.                         for ( y = new_bottom + 1  ; y<=bottom_field; y++ ) {
  84.                                 point(50,y);
  85.                                 switch (terminal_type) {
  86.                                 case adm3:
  87.                                         printf(blank_line);
  88.                                         break;
  89.                                 case vis400:
  90.                                 case vt52:
  91.                                         printf("\33[K");
  92.                                         break;
  93.                                 }
  94.                         };
  95.         };
  96.         bottom_field = new_bottom;
  97. }
  98.  
  99. cle3r_left()
  100. {
  101.         int i;
  102.         if ( terminal_type != hardcopy ) {
  103.                 for ( i = 19 ; i<=24; i++ ) {
  104.                         if ( left_line[i] ) {
  105.                                 switch (terminal_type) {
  106.                                 case vt52:
  107.                     point(1,i);
  108.                     printf(blank_line);
  109.                     break;
  110.                                 }
  111.                                 left_line[i] = false;
  112.                         }
  113.                 }
  114.         }
  115. }
  116.  
  117.  
  118.  
  119. cle2r_screen()
  120. {
  121.         switch ( terminal_type ) { /*clear screen*/
  122.         case vis400:
  123.                 printf("\33[2J");
  124.                 break;
  125.         case vt52: 
  126.                 printf("\33[H\33[J");
  127.                 break;
  128.         case adm3: 
  129.                 putchar('\32'); 
  130.                 break;
  131.         }; /*switch (*/
  132.         point(1,1);
  133. }
  134.  
  135.  
  136.  
  137. error_message()
  138. {
  139.         point(1,24);
  140. }
  141.  
  142. get_token(line, Index0, Value0, Token0)
  143. char *line;
  144. int *Index0, *Value0;
  145. char *Token0;
  146. {
  147.         int index, value; 
  148.         char token;
  149.         index = *Index0;
  150.         value = 0;
  151.         token = ' ';
  152.         while (line[index]==' ' && (index < 80) ) index = index+1;
  153.         if ( index<80 ) {
  154.                 if ( (line[index] < '0') || (line[index] > '9') )
  155.                         value = 1;
  156.                 else {
  157.                         while (line[index] >='0' && (line[index] <= '9') ) {
  158.                                 value = 10*value + line[index] - '0';
  159.                                 index = index+1;
  160.                         };
  161.                 };
  162.                 token = line[index];
  163.                 index = index+1;
  164.         }
  165.         while (line[index]!=' ' && (index<80) ) index= index+1;
  166.         while (line[index] == ' ' && (index < 80) ) index = index+1;
  167.         *Index0 = index; 
  168.         *Value0 = value; 
  169.         *Token0 = token;
  170. }
  171.  
  172.  
  173. struct helpst {
  174.         char *cmd, *does;
  175. };
  176.  
  177. struct helpst help0[] = {
  178.         {       "B",    "Bld Battlestar(s)    75"},
  179.         {       "C",    "Bld Cruiser(s)       16"},
  180.         {       "H",    "Help"                   },
  181.         {       "R",    "Range Research"         },
  182.         {       "S",    "Bld Scout(s)          6"},
  183.         {       "V",    "Velocity Research"      },
  184.         {       "W",    "Weapons Research"       },
  185.         {       ">M",   "Redraw Map"             },
  186.         {       ">R",   "Research summary"       },
  187.         {       0,      0                        }
  188. };
  189.  
  190. struct helpst help1[] = {
  191.         {       "B",    "Blast Planet"           },
  192.         {       "C",    "Colony summary"         },
  193.         {       "D",    "TaskForce Destination"  },
  194.         {       "G",    "Go on (done)"           },
  195.         {       "H",    "Help"                   },
  196.         {       "J",    "Join TaskForces"        },
  197.         {       "L",    "Land transports"        },
  198.         {       "M",    "Redraw Map"             },
  199.         {       "N",    "New TaskForce"          },
  200.         {       "Q",    "Quit"                   },
  201.         {       "R",    "Research summary"       },
  202.         {       "S",    "Star summary"           },
  203.         {       "T",    "TaskForce summary"      },
  204.         {       0,      0                        }
  205. };
  206.  
  207. struct helpst help2[] = {
  208.         {       "C",    "Colonies"               },
  209.         {       "G",    "Go on (done)"           },
  210.         {       "H",    "Help"                   },
  211.         {       "M",    "Map"                    },
  212.         {       "O",    "Odds"                   },
  213.         {       "R",    "Research summary"       },
  214.         {       "S",    "Star summary"           },
  215.         {       "T",    "TaskForce summary"      },
  216.         {       "W",    "Withdraw"               },
  217.         {       0,      0,                       }
  218. };
  219.  
  220. struct helpst help3[] = {
  221.         {       "B",    "Break off Attack"       },
  222.         {       "C",    "Colony summary"         },
  223.         {       "G",    "Go on (done)"           },
  224.         {       "H",    "Help"                   },
  225.         {       "J",    "Join TFs"               },
  226.         {       "M",    "Redraw Map"             },
  227.         {       "N",    "New TF"                 },
  228.         {       "R",    "Research summary"       },
  229.         {       "S",    "Star summary"           },
  230.         {       "T",    "TaskForce summary"      },
  231.         {       0,      0                        }
  232. };
  233.  
  234. struct helpst help4[] = {
  235.         {       "A",    "Bld Adv. Missle Base 35"},
  236.         {       "B",    "Bld Battlestar(s)    70"},
  237.         {       "C",    "Bld Cruiser(s)       16"},
  238.         {       "H",    "Help"                   },
  239.         {       "I",    "Invest                3"},
  240.         {       "M",    "Bld Missle Base(s)    8"},
  241.         {       "R",    "Range Research"         },
  242.         {       "S",    "Bld Scout(s)          6"},
  243.         {       "T",    "Bld Transports"         },
  244.         {       "V",    "Vel Research"           },
  245.         {       "W",    "Weapons Research"       },
  246.         {       ">C",   "Colony summary"         },
  247.         {       ">M",   "Redraw Map"             },
  248.         {       ">R",   "Research summary"       },
  249.         {       ">S",   "Star summary"           },
  250.         {       0,      0                        }
  251. };
  252.  
  253. help(which)
  254. int which;
  255. {
  256.         struct helpst *h;
  257.         int j;
  258.  
  259.         j = 1;
  260.         point(50, j++);
  261.         if (which == 0) h = help0;
  262.         if (which == 1) h = help1;
  263.         if (which == 2) h = help2;
  264.         if (which == 3) h = help3;
  265.         if (which == 4) h = help4;
  266.         while (h->cmd != 0) {
  267.                 printf("%2s - %-25s", h->cmd, h->does);
  268.                 point(50, j++);
  269.                 h++;
  270.         }
  271.         clear_field();
  272. }
  273.  
  274.  
  275. on_board(x,y)
  276. {
  277.         int i;
  278.         int starnum;
  279.         board[x][y].tf=' ';
  280.         i=1;
  281.         do {
  282.                 if ( (tf[player][i].dest!=0) && (tf[player][i].x==x) 
  283.                                                         && (tf[player][i].y==y
  284.                     ) ) {
  285.                         if ( board[x][y].tf==' ' )
  286.                                 board[x][y].tf= i+'a'-1;
  287.                         else {
  288.                                 board[x][y].tf='*';
  289.                                 i=27;
  290.                         };
  291.                 };
  292.                 i=i+1;
  293.         } 
  294.         while (i <= 26);
  295.         if ( board[x][y].star != '.' ) {
  296.                 board[x][y].enemy = ' ';
  297.                 starnum= board[x][y].star - 'A' +1;
  298.                 if ( col_stars[starnum][player] != 0 )
  299.                         board[x][y].enemy = '@';
  300.         };
  301.         update_board(x,y,both);
  302. }
  303.  
  304. pause()
  305. {
  306.         char dummy;
  307.         point(1,18);
  308.         printf("Press any key to continue  ");
  309.         get_char(&dummy);
  310. }
  311.  
  312.  
  313. pr3nt_tf(i)
  314. {
  315.         int x, y;
  316.         if ( (i!=0) && (i<27) ) {
  317.                 if ( tf[player][i].dest != 0 ) {
  318.                         printf("TF%c:", i+'a'-1);
  319.                         x=tf[player][i].x; 
  320.                         y=tf[player][i].y;
  321.                         if ( tf[player][i].eta==0 )
  322.                                 putchar(tf[player][i].dest+'A'-1);
  323.                         else
  324.                                 putchar(' ');
  325.                         printf("(%2d,%2d)               ",x,y);
  326.                         point(x_cursor + 14, y_cursor);
  327.                         x_cursor = x_cursor - 14;
  328.                         disp_tf(&tf[player][i]);
  329.                         if ( tf[player][i].eta != 0 ) {
  330.                                 printf("%c2m", 0x9b);
  331.                                 printf("%c%d",
  332.                                 tf[player][i].dest+'A'-1, tf[player][i].eta);
  333.                                 printf("%c0m", 0x9b);
  334.                         };
  335.                         point(x_cursor, y_cursor+1);
  336.                 };
  337.         };
  338. }
  339.  
  340.  
  341. pr5nt_star(stnum)
  342. {
  343.         boolean see;
  344.         int i, x, y;
  345.         tplanet *p;
  346.         if ( (stnum!=0) && (stnum<=nstars) ) {
  347.                 if ( (y_cursor + 3 + tf_stars[stnum][player] + tf_stars[stnum][
  348.                     ENEMY] ) > 19 ) {
  349.                         clear_field();
  350.                         pause();
  351.                         point(50,1);
  352.                 };
  353.                 if ( stars[stnum].visit[player]==true ) {
  354.                         see=false;
  355.                         printf("----- star %c -----            ", stnum+'A'-1)
  356.                                 ;
  357.                         point(50, y_cursor + 1);
  358.                         x=stars[stnum].x;
  359.                         y=stars[stnum].y;
  360.                         if ( tf_stars[stnum][player] !=0 ) {
  361.                                 see = true;
  362.                                 for ( i=1 ; i<=26; i++ ) {
  363.                                         if (tf[player][i].dest==stnum && tf[player][i].eta == 0)
  364.                                         {
  365.                                                 printf("TF%c                           ", i+'a'-1);
  366.                                                 point(55,y_cursor);
  367.                                                 disp_tf(&tf[player][i]);
  368.                                                 point(50, y_cursor + 1);
  369.                                         };
  370.                                 };
  371.                         };
  372.                         if ( ! see )
  373.                                 see = col_stars[stnum][player] != 0;
  374.                         if ( see && (tf_stars[stnum][ENEMY] != 0) ) {
  375.                                 i=1;
  376.                                 while(tf[ENEMY][i].eta!=0 ||
  377.                                    (tf[ENEMY][i].dest!=stnum) )
  378.                                         i=i+1;
  379.                                 printf(" EN:                          ");
  380.                                 point(55,y_cursor);
  381.                                 disp_tf(&tf[ENEMY][i]);
  382.                                 point( 50, y_cursor + 1);
  383.                         };
  384.                         p=stars[stnum].first_planet;
  385.                         if ( p==nil ) {
  386.                                 printf("  no useable planets          ");
  387.                                 point(50,y_cursor + 1);
  388.                         }
  389.                         else {
  390.                                 while ( p!=nil ) {
  391.                                         putchar(' ');
  392.         if ( ((y_cursor > 21) && (x_cursor >= 50)) ||
  393.             (y_cursor > 24) ) {
  394.                 pause();
  395.                 clear_field();
  396.                 point(50,1);
  397.         };
  398.         printf("%d:%2d                         ", p->number, p->psee_capacity);
  399.         point(x_cursor + 5, y_cursor);
  400.         x_cursor = x_cursor - 5;
  401.         if ( p->psee_capacity==0 )
  402.                 printf(" Decimated");
  403.         else if ( (p->team==none) && see )
  404.                 printf(" No colony");
  405.         else if ( p->team==player ) {
  406.                 printf("(%2d,/%3d)", p->inhabitants, p->iu);
  407.                 if ( p->conquered )
  408.                         printf("Con");
  409.                 else
  410.                         printf("   ");
  411.                 if ( p->mb!=0 )
  412.                         printf("%2dmb", p->mb);
  413.                 else
  414.                         printf("    ");
  415.                 if ( p->amb!=0 )
  416.                         printf("%2damb", p->amb);
  417.         } 
  418.         else if ( (p->team==ENEMY) && see ) {
  419.                 printf("*EN*");
  420.                 if ( see && p->conquered ) {
  421.                         printf("Conquered");
  422.                 } 
  423.                 else
  424.                         printf("   ");
  425.                 if ( p->under_attack ) {
  426.                         if ( p->mb != 0 )
  427.                                 printf("%2dmb", p->mb);
  428.                         else
  429.                                 printf("    ");
  430.                         if ( p->amb != 0 )
  431.                                 printf("%2damb", p->amb);
  432.                 };
  433.         };
  434.         point(x_cursor,y_cursor + 1);
  435.  
  436.                                         p=p->next;
  437.                                 };
  438.                         }
  439.                 }
  440.         }
  441. }
  442.  
  443.  
  444. swap(a, b)
  445. int *a, *b;
  446. {
  447.         int t;
  448.  
  449.         t = *a;
  450.         *a = *b;
  451.         *b = t;
  452. }
  453.  
  454.